import { useState } from "react"

import http from "@/api/helper/request"

import { IAuditRecordParams, ILockRecordParams, IQueryListParams, IResponseItem } from "./types"

const useApi = () => {
	const [loading, setLoading] = useState(false)

	async function generalHttp<T>(url: string, body: object | undefined, config: object = {}) {
		setLoading(true)
		let ret = await http.post<T>(url, body, config)
		setLoading(false)
		return ret
	}

	const getList = (body?: IQueryListParams) =>
		generalHttp<Business.TableResourceType<IResponseItem>>("/memberTransfer/selectPage", body)

	const updateMemberAuditLock = (body?: ILockRecordParams) => generalHttp("/memberTransfer/lockOrder", body)

	const auditRecord = (body?: IAuditRecordParams) => generalHttp("/memberTransfer/audit", body)

	const getDetail = (body?: { id: string }) => generalHttp("/memberTransfer/detail", body)

	return {
		getList,
		getDetail,
		updateMemberAuditLock,
		auditRecord,
		loading
	}
}

export default useApi
